﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using UAC;
using UAC.Operation;

namespace UACManager
{
    public partial class OperationDefForm : Form
    {
        private int documentDefId;
        public OperationDef OperationDef { get; private set; }
        public OperationDefForm(int documentDefId)
        {
            InitializeComponent();
            this.documentDefId = documentDefId;
            this.tDocDefID.Text = this.documentDefId.ToString();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            string opdefid = tOpDefID.Text;
            string name = tName.Text;
            string desc = tDesc.Text;
            string ocid = tOCID.Text;
            if (opdefid.Length == 0 || name.Length == 0)
            {
                MessageBox.Show("OperationDefID/Name不允许为空！", "警告");
                return;
            }

            int _opdefid = 0;
            if (!Int32.TryParse(opdefid, out _opdefid))
            {
                MessageBox.Show("OperationDefID应该为数字！", "警告");
                return;
            }
            try
            {
                this.OperationDef = Utils.CreateOperationDef(this.documentDefId, _opdefid, name, desc, string.IsNullOrEmpty(ocid) ? -1 : Convert.ToInt32(ocid));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "警告");
                return;
            }
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }
    }
}
